package com.ldq.imooc.basics.multiThread;

/**
 * @Author : 李道泉
 * @Description :
 * @Date : 2018/4/24 10:55
 * @Modified by :
 */

class MyThread2 implements Runnable {

    //5张火车票
    private int ticketsCount = 5;

    @Override
    public void run() {

        while (ticketsCount > 0) {
            //如果有票，就卖掉一张
            ticketsCount--;
            System.out.println(Thread.currentThread().getName() + "：卖了一张票，余票为：" + ticketsCount);

        }
    }
}

public class TicketsRunnable {

    public static void main(String[] args) {

        MyThread2 mt = new MyThread2();
        MyThread2 mt2 = new MyThread2();
        MyThread2 mt3 = new MyThread2();
        Thread th1 = new Thread(mt, "窗口1");
        Thread th2 = new Thread(mt2, "窗口2");
        Thread th3 = new Thread(mt3, "窗口3");

        th1.start();
        th2.start();
        th3.start();
    }
}
